package com.beta.elephant.vo;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.io.Serializable;

/**
 * 请求返回结果结构类
 *
 * @author kevin_zhang
 */
@ApiModel("返回信息")
public class ResultVO<T> implements Serializable {

    @ApiModelProperty(value="返回码")
    private Integer code;

    @ApiModelProperty(value="返回消息")
    private String msg;

    @ApiModelProperty(value="返回数据")
    private T data;

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public ResultVO() {
        this.setCode(200);
        this.setMsg("成功");
    }

    public static ResultVO success() {
        return new ResultVO();
    }

    public static <T> ResultVO<T> success(T result) {
        ResultVO<T> resultVO = new ResultVO();
        resultVO.setData(result);
        return resultVO;
    }

    public static ResultVO failure(BaseResultCode resultCode) {
        ResultVO resultVO = new ResultVO();
        resultVO.setCode(resultCode.getCode());
        resultVO.setMsg(resultCode.getMsg());
        return resultVO;
    }

    public static <T> ResultVO<T> failure(BaseResultCode resultCode, T result) {
        ResultVO<T> resultVO = new ResultVO();
        resultVO.setCode(resultCode.getCode());
        resultVO.setMsg(resultCode.getMsg());
        resultVO.setData(result);
        return resultVO;
    }

    public static ResultVO failure(Integer code, String msg) {
        ResultVO resultVO = new ResultVO();
        resultVO.setCode(code);
        resultVO.setMsg(msg);
        return resultVO;
    }

    public static <T> ResultVO<T> failure(Integer code, String msg, T result) {
        ResultVO<T> resultVO = new ResultVO();
        resultVO.setCode(code);
        resultVO.setMsg(msg);
        resultVO.setData(result);
        return resultVO;
    }
}
